<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>堆箱子</title>
</head>
<body>
  <script>
    function fn(box) {
      const hSort = box.sort((a, b) => a[2] - b[2]);
      const cache = new Array(box.length).fill(0);
      let ans = 0;
      for (let i = box.length - 1; i >= 0; i--) {
        let res = 0;
        const tempBox = hSort[i];
        for (let j = i + 1; j < box.length; j++) {
          const currBox = hSort[j];
          if (currBox[0] > tempBox[0] && currBox[1] > tempBox[1] && currBox[2] > tempBox[2]) {
            res = Math.max(res, cache[j])
          }
        }
        cache[i] = hSort[i][2] + res
        ans = Math.max(cache[i], ans)
      }
      return ans
    }
    console.log(fn([[1, 1, 1], [2, 2, 2], [3, 3, 3]]))
  </script>
</body>
</html>